import {defineStore} from 'pinia'
import discoveryApi, {type properMdeol, type collectMdeol} from '@/api/discovery'

const useDiscoveryStore = defineStore('discovery',{
    state(){
        return {
            seconList:<properMdeol[]>[],
            videoList:<collectMdeol>{},
            themeList:<collectMdeol>{}
        }
    },
    actions:{
        // 二级分类
        async getMomberList(){
            try {
                let result = await discoveryApi.properties()
                this.seconList = result
                
            } catch (error) {
                console.error(error);
                return Promise.reject(error)
            }
        },
        // 视频初始化
        async getVideoList(pageSize:number,pageNum:number,tagType:string,data){
            try {
                let result = await discoveryApi.collect(pageSize,pageNum,tagType,data)
                
                this.videoList = result
            } catch (error) {
                console.error('初始化视频失败')
                return Promise.reject(error)
            }
        },
        // 主题初始化
        async getThemeList(){
            try {
                let result = await discoveryApi.theme()
                
                this.themeList = result
            } catch (error) {
                console.error('初始化视频失败')
                return Promise.reject(error)
            }
        }
    },
    getters:{
        getcontent:(state) => {
            return state.videoList.content || []
        }
    }
})

export default useDiscoveryStore